<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
</head>
<body>
  用户名：<input type="text" id="username">
  密码：<input type="text" id="password">
  <button class="reguser">注册</button>
  <button class="login">登录</button>
  <script>

    $(function() {
      function getUserInfo() {
        return {
          username: $('#username').val(),
          password: $('#password').val()
        }
      }

      $('.reguser').on('click', () => {
        let userinfo = getUserInfo()
        $.ajax({
          url: 'http://127.0.0.1:3000/api/reguser',
          type: 'POST',
          data: userinfo,
          success: (res) => {
            console.log(res)
          }
        })
      })
      
      $('.login').on('click', () => {
        let userinfo = getUserInfo()
        $.ajax({
          url: 'http://127.0.0.1:3000/api/login',
          type: 'POST',
          data: userinfo,
          success: (res) => {
            console.log(res)
          }
        })
      })
    })
  </script>
</body>
</html>